﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QVBoxLayout>
#include <QLabel>
#include <QThread>
#include <qtmaterialtabs.h>
#include <qtmaterialdrawer.h>
#include <qtmaterialraisedbutton.h>
#include <WidgetPFD.h>
#include "waterwave.h"
#include "qcustomplot.h"
#include "axistag.h"
#include "tcpclient.h"
#include "tcpclient2.h"
#include "datachange.h"

QT_BEGIN_NAMESPACE
namespace Ui
{
    class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    void addLogMess(QString mes, Qt::GlobalColor color);
    void addLogMessIn(int valuse, Qt::GlobalColor color);
    ~MainWindow();

private slots:
    void on_action_4_triggered();

private:
    Ui::MainWindow *ui;
    QtMaterialTabs *m_tabs;
    QtMaterialDrawer *m_drawer;
    QtMaterialRaisedButton *modelButton[10];
    WidgetPFD *m_widgetPFD;
    waterwave *m_waterwave_1;
    waterwave *m_waterwave_2;
    waterwave *m_waterwave_3;
    waterwave *m_waterwave_4;

    QTimer *timer; // 定时器
    QTimer *Activity;
    QPointer<QCPGraph> mGraph1;
    QPointer<QCPGraph> mGraph2;
    QPointer<QCPGraph> mGraph3;
    QPointer<QCPGraph> mGraph4;
    AxisTag *mTag1;
    AxisTag *mTag2;
    AxisTag *mTag3;
    AxisTag *mTag4;

    QPointer<QCPGraph> mGraph01;
    QPointer<QCPGraph> mGraph02;
    QPointer<QCPGraph> mGraph03;
    QPointer<QCPGraph> mGraph04;
    AxisTag *mTag01;
    AxisTag *mTag02;
    AxisTag *mTag03;
    AxisTag *mTag04;

    tcpclient *m_tcpclient;   // 客户端1 传命令传感器数据
    tcpclient2 *m_tcpclient2; // 客户端2 传声纳数据
    QThread *m_tcpThread;
    QThread *m_tcpThread2;
    QDateTime *m_datatime;

    datachange *m_datachange; // 声纳数据转fft类
    QThread *m_datachangeThread;

private:
    int ck = 0;

signals:
    void model_num(int i);
    void tcpcreat();
    void tcpwrite(const char *data, qint64 len);
    void tcpconnect(QString, ushort);
    void tcpdisconnect();

    void tcp2creat();
    void tcp2write(const char *data, qint64 len);
    void tcp2connect(QString, ushort);
    void tcp2disconnect();
    void setfilename(QString);
    void setsavefileflag(bool);

    void creatdatachange();

private:
    void model_select();
    void init_form();
    void creat_customplot();

private:
    void init_model1();
    void init_model2();
    void init_model3();

    void receive_Control_Signal_H();
    void receive_Control_Signal_L();
    void receive_Control_Cur_Time();
    void receive_Control_Get_Time();
    void receive_Control_Set_SignalType_H();
    void receive_Control_Get_SignalType_H();
    void receive_Control_Set_SignalType_L();
    void receive_Control_Get_SignalType_L();
    void receive_Set_TVG_Gain();
    void receive_Get_TVG_Gain();
    void receive_SetWorkPower();
    void receive_GetWorkPower();
    void receive_SetTVG_H();
    void receive_GetTVG_H();
    void receive_SetTVG_L();
    void receive_GetTVG_L();
    void receive_SetWorkMode();
    void receive_GetWorkMode();
    void receive_GetTEMP();
    void receive_GetHumidity();
    void receive_GetSASTankStatus();
    void receive_GetPressureHeight();
    void receive_SetPressureHeightEn();
    void receive_GetPressureHeightEn();
    void receive_GetAltitudeSensor();
    void receive_SetAltitudeSensorEn();
    void receive_GetAltitudeSensorEn();
    void receive_SetSoundVelocity();
    void receive_GetSoundVelocity();
    void receive_GetAltimeter();
    void receive_LSnoar();
    void receive_RSnoar();
    void receive_infromtion();
    void receive_Voltage_And_Current();
    void receive_Activity();

    void display_Control_Get_Time();
    void display_GetSignalType_H();
    void display_GetSignalType_L();
    void display_Get_TVG_Gain();
    void display_GetWorkPower();
    void display_GetTVG_H();
    void display_GetTVG_L();
    void display_GetWorkMode();
    void display_GetTemp();
    void display_GetHumidity();
    void display_GetSASTankStatus();
    void display_GetPressureHeight();
    void display_SetPressureHeightEn();
    void display_GetPressureHeightEn();
    void display_GetAltitudeSensor();
    void display_SetAltitudeSensorEn();
    void display_GetAltitudeSensorEn();
    void display_SetSoundVelocity();
    void display_GetSoundVelocity();
    void display_GetAltimeter();
    void display_SASTankStatus();
    void display_SonarWorkingStatus();
    void display_PressureHeight();
    void display_AltitudeSensor();
    void display_Altimeter();
private slots:
    void m_tcpclient_connected();
    void m_tcpclient_disconnected();
    void m_tcpclient2_connected();
    void m_tcpclient2_disconnected();
    void displaysomthing();
    void Activity_timer();
    void on_pushButton_clicked();
    void setfilename1(bool checked);
    void on_pushButton_Control_Signal_clicked();
    void on_pushButton_Cur_Time_clicked();
    void on_actionabout_triggered();
    void on_pushButton_bSingle_1_clicked(bool checked);
    void on_pushButton_bSingle_2_clicked(bool checked);
    void on_pushButton_bSingle_3_clicked(bool checked);
    void on_pushButton_bSingle_4_clicked(bool checked);
    void on_pushButton_bAltitudeEnable_clicked(bool checked);
    void on_pushButton_bAltimeterEnable_clicked(bool checked);
    void on_pushButton_CONNECT_clicked();
    void on_pushButton_floder_clicked();
    void on_checkBox_floder_clicked(bool checked);
    void on_pushButton_SetTVG_Gain_clicked();
    void on_pushButton_SaveEnable_clicked(bool checked);
    void on_calibration_clicked();
    void on_pushButton_GetSysTime_clicked();
    void on_pushButton_SetSignalType_clicked();
    void on_pushButton_GetSignalType_clicked();
    void on_pushButton_GetTVG_Gain_clicked();
    void on_pushButton_GetTEMP_clicked();
    void on_pushButton_SetWorkPower_clicked();
    void on_pushButton_GetWorkPower_clicked();
    void on_pushButton_SetTVG_clicked();
    void on_pushButton_GetTVG_clicked();
    void on_pushButton_SetWorkMode_clicked();
    void on_pushButton_GetWorkMode_clicked();
    void on_pushButton_L_Sonar_clicked();
    void on_pushButton_Triger_Sonar_clicked();
    void on_pushButton_GetHumidity_clicked();
    void on_pushButton_GetSASTankStatus_clicked();
    void on_pushButton_GetPressureHeight_clicked();
    void on_pushButton_GetAltitudeSensor_clicked();
    void on_pushButton_bPressureEnable_clicked(bool checked);
    void on_pushButton_Working_Sonr_clicked(bool checked);
    // void setfilename();
    // void on_pushButton_Working_Status_clicked();
    // void on_pushButton_Working_Status_clicked();
    // void on_pushButton_bPressureEnable_clicked();
    // void on_pushButton_SaveEnable_clicked();
    void on_pushButton_Working_Status_clicked(bool checked);
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_Activity_clicked(bool checked);
    void on_pushButton_L_delay_clicked();
    void on_pushButton_GetAltimeter_2_clicked(bool checked);
    void on_pushButton_SetSignalType_3_clicked();
    void on_pushButton_GetSignalType_3_clicked();
    void on_pushButton_SetTVG_2_clicked();
    void on_pushButton_GetTVG_2_clicked();
    void on_pushButton_Control_Signal_2_clicked();
    void on_GPS_Source_clicked();

    void on_GPS_UTC_clicked();

    void on_HCC_PPS_TIME_2_clicked();

    void on_HCC_PPS_MODE_clicked();

    void on_HCC_PPS_TIME_clicked();

    void on_HCC_PPS_MODE_2_clicked();

public slots:
    void onAltitudeUpdated(int altitude);
    void onUTCUpdated(uint64_t utc);
    void onStateUpdated(int state);
    void onStateUpdated_Mode(uint8_t state);
};
#endif // MAINWINDOW_H
